<template>
  <div class="cont-add-dialog">
    <div class="header">
      <span class="title">标签编辑</span>
      <span class="close" @click="emit('close')"></span>
    </div>
    <div class="dia">
      <div class="content">
        <div class="list">
          <div class="xq">
            <div class="txt">标签类别</div>
            <div>
              <el-select
                v-model="state.pm.categoryId"
                placeholder="请选择"
                :disabled="props.vt == 0"
              >
                <el-option
                  v-for="item in state.lxList"
                  :key="item.tagCategoryId"
                  :label="item.tagCategoryName"
                  :value="item.tagCategoryId"
                />
              </el-select>
            </div>
            <div class="txt">标签名称</div>
            <div>
              <el-input
                v-model="state.pm.tagName"
                placeholder="请输入"
              ></el-input>
            </div>
            <div class="txt">模版类别</div>
            <div>
              <el-select v-model="state.pm.templateId" placeholder="请选择">
                <el-option
                  v-for="item in moptions"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </div>
            <div
              class="txt"
              v-if="
                state.pm.templateId == 'WZ' ||
                state.pm.templateId == 'TW' ||
                state.pm.templateId == 'BHQ'
              "
            >
              标签描述
            </div>
            <div
              v-if="
                state.pm.templateId == 'WZ' ||
                state.pm.templateId == 'TW' ||
                state.pm.templateId == 'BHQ'
              "
            >
              <el-input
                type="textarea"
                v-model="state.pm.tempTextdesc"
                :rows="2"
                placeholder="请输入"
              ></el-input>
            </div>

            <div class="txt" v-if="state.pm.templateId == 'TW'">图片</div>
            <div v-if="state.pm.templateId == 'TW'">
              <el-upload
                :file-list="state.picList"
                list-type="picture-card"
                :http-request="upfile"
                :limit="1"
                :on-remove="picremove"
                :on-preview="preview"
              >
                <el-icon>
                  <Plus />
                </el-icon>
              </el-upload>
            </div>

            <div class="txt" v-if="state.pm.templateId == 'ZP'">实时抓拍</div>
            <div class="sszp" v-if="state.pm.templateId == 'ZP'">
              <div class="zpone" v-for="item in 3" :key="item">
                <img
                  class="empimg"
                  src="/images/zp.png"
                  v-if="state.zps.length < item"
                />
                <img class="img" :src="item" v-if="state.zps.length >= item" />
              </div>
            </div>

            <div
              class="txt"
              v-if="state.pm.templateId == 'SP' || state.pm.templateId == 'ZP'"
            >
              视频
            </div>
            <div
              v-if="state.pm.templateId == 'SP' || state.pm.templateId == 'ZP'"
            >
              <el-select v-model="state.pm.tempDeviceId" placeholder="请选择">
                <el-option
                  v-for="item in state.cmList"
                  :key="item.cameraId"
                  :label="item.cameraName"
                  :value="item.cameraId"
                />
              </el-select>
            </div>
          </div>
        </div>
        <div class="btns">
          <el-button class="cusb1" @click="emit('close')">取消</el-button>
          <el-button class="cusb1" @click="save">确定</el-button>
        </div>
      </div>
    </div>
    <el-image-viewer
      style="z-index: 5000 !important"
      v-if="state.imageUrl != ''"
      :on-close="closeViewer"
      :url-list="[state.imageUrl]"
    />
  </div>
</template>

<script setup>
import { ElMessage, ElMessageBox } from "element-plus";
const props = defineProps({
  vt: Number,
});
const emit = defineEmits(["close", "reget"]);
const state = reactive({
  title: "标签编辑",
  pm: { templateId: "WZ", tagName: "", categoryId: "" },
  zps: [],
  lxList: [],
  cmList: [],
  picList: [],
  imageUrl: "",
});
// const moptions = [{ value: 'WZ', label: '文字版' }, { value: 'TW', label: '图文版' }, { value: 'SP', label: '视频版' }, { value: 'ZP', label: '抓拍视频版' }, { value: 'CBTKQ', label: '船舶停靠区' }, { value: 'JMQ', label: '居民区' }, { value: 'TCC', label: '停车场' }, { value: 'JYXF', label: '救援消防' }, { value: 'BHQ', label: '保护区' }, { value: 'BGQ', label: '办公区' }];
const moptions = [
  { value: "ptjksb", label: "普通监控设备" },
  { value: "znjksb", label: "智能设备监控" },
  { value: "zdjy", label: "监控设备占道经营" },
  { value: "jcdlxx", label: "基础地理信息" },
  { value: "crk", label: "出入口" },
  { value: "xxyl", label: "休闲娱乐" },
  { value: "WZ", label: "文字版" },
  { value: "TW", label: "图文版" },
  { value: "SP", label: "视频版" },
  { value: "ZP", label: "抓拍视频版" },
  { value: "CBTKQ", label: "船舶停靠区" },
  { value: "JMQ", label: "居民区" },
  { value: "TCC", label: "停车场" },
  { value: "JYXF", label: "救援消防" },
  { value: "BHQ", label: "保护区" },
  { value: "BGQ", label: "办公区" },
];
const save = () => {
  // if (state.pm.categoryId == "") {
  //   ElMessage.error('请选择标签类型')
  //   return
  // }
  // if (state.pm.tagName == "") {
  //   ElMessage.error('请输入标签名称')
  //   return
  // }
  // if ((state.pm.templateId == "WZ" || state.pm.templateId == "TW") && (!state.pm.tempTextdesc || state.pm.tempTextdesc == "")) {
  //   ElMessage.error('请输入标签描述')
  //   return
  // }
  // if (state.pm.templateId == "TW" && (!state.pm.tempPic || state.pm.tempPic == "")) {
  //   ElMessage.error('请选择图片')
  //   return
  // }
  // if ((state.pm.templateId == "SP" || state.pm.templateId == "ZP") && (!state.pm.tempDeviceId || state.pm.tempDeviceId == "")) {
  //   ElMessage.error('请选择视频')
  //   return
  // }
  //构造点位信息
  let store = useMyStore();
  let dxm = store.params.dxm || {};
  if (!dxm.type) {
    ElMessage.error("获取坐标数据异常");
    return;
  }
  state.pm.graphType =
    dxm.type == 1 ? "point" : dxm.type == 2 ? "line" : "polygon";
  let graphData = {};
  graphData.type = dxm.type;
  let w = dxm.w;
  let h = dxm.h;
  let data = Array.from(dxm.data);
  for (let i = 0; i < data.length; i++) {
    data[i].x = (1.0 * data[i].x) / w;
    data[i].y = (1.0 * data[i].y) / h;
  }
  graphData.data = data;
  state.pm.graphData = JSON.stringify(graphData);
  state.pm.cameraId = dxm.vid; //当前视频id
  state.pm.ptzPanpos = dxm.ptz.p;
  state.pm.ptzTiltpos = dxm.ptz.t;
  state.pm.ptzZoompos = dxm.ptz.z;
  //保存数据
  useApi
    .post("/arhome/camera/settag", state.pm)
    .then((res) => {
      emit("reget");
    })
    .catch((err) => {
      ElMessage.error(err.data.message);
    });
};
const upfile = (config) => {
  let data = new FormData();
  data.append("picfile", config.file);
  useApi
    .post("/arhome/common/picupload", data)
    .then((res) => {
      state.pm.tempPic = res.data.resString;
      state.picList = [{ name: "pic", url: res.data.resString }];
    })
    .catch((err) => {
      ElMessage.error(err.status + " " + err.statusText);
      state.pm.tempPic = "";
      state.picList = [];
    });
};
const picremove = () => {
  state.pm.tempPic = "";
  state.picList = [];
};
const preview = (up) => {
  state.imageUrl = up.url;
};
const closeViewer = () => {
  state.imageUrl = "";
};
const getLeixing = () => {
  useApi
    .post("/arhome/system/tagcategory/list", {
      tagCategoryName: "",
      tagCategoryState: null,
    })
    .then((res) => {
      state.lxList = res.data.tagCategory4SysList || [];
    });
};
const getCamara = () => {
  useApi.post("/dynamicview/ar/highandlows", {}).then((res) => {
    state.cmList = [...res.data.highList, ...res.data.lowList];
  });
};
onMounted(() => {
  if (props.vt == 0) {
    state.title = "标签信息";
  } else {
    state.title = "标签编辑";
  }
  getLeixing();
  getCamara();
});
</script>

<style lang="scss" scoped>
.cont-add-dialog {
  width: 400px;
  height: 540px;
  background: url("/images/new/tag/tagbg.png") no-repeat;
  background-size: 100% 100%;
  .header {
    width: 100%;
    height: 52.5px;
    position: relative;
    background: url("/images/new/tag/header.png") no-repeat;
    background-size: 100% 100%;
    .title {
      display: inline-block;
      height: 100%;
      padding-left: 25px;
      font-family: YouSheBiaoTiHei;
      font-size: 25px;
      color: #ffffff;
      line-height: 60px;
    }

    .close {
      width: 40px;
      height: 40px;
      position: absolute;
      right: 16px;
      top: 20.5px;
      line-height: 40px;
      text-align: center;
      color: #fff;
      font-size: 30px;
      cursor: pointer;
    }
  }
}

.dia {
  width: 100%;
  height: calc(100% - 52.5px);
  // display: flex;
  // flex-direction: column;
  padding: 0 30px 20px 30px;
  .content {
    width: 100%;
    height: 100%;
    .list {
      width: 100%;
      height: calc(100% - 47px);
      padding: 10px 10px;
      display: flex;
      flex-direction: column;
      overflow-y: auto;
      .txt {
        height: 28px;
        display: flex;
        align-items: center;
        font-weight: 600;
        font-size: 14px;
        color: #ffffff;
      }

      .sszp {
        display: flex;
        justify-content: space-between;

        .zpone {
          width: 80px;
          height: 90px;
          display: flex;
          justify-content: center;
          align-items: center;
          background: linear-gradient(
            0deg,
            rgba(11, 81, 127, 0.5) 0%,
            rgba(11, 81, 127, 0.5) 100%
          );
          box-shadow: inset 0px 0px 16px 0px rgba(0, 61, 99, 0.87);

          .empimg {
            width: 28px;
            height: 28px;
          }

          .img {
            width: 80px;
            height: 90px;
          }
        }
      }
    }
    .btns {
      height: 47px;
      display: flex;
      justify-content: center;
      align-items: center;
      .cusb1,
      .cusb2 {
        width: 40%;
        height: 47px;
        background: url("/images/add/btnbg.png") no-repeat;
        background-size: 100% 100%;
      }
    }
  }
}

:deep(.el-select) {
  width: 260px;
  --el-input-text-color: #ffffff;

  .el-select__wrapper {
    background: #003d6399;
    color: #ffffff;
    border: none;
    box-shadow: none;
    border-radius: 0px !important;
  }
}

:deep(.el-input) {
  --el-input-text-color: #ffffff;
  --el-input-bg-color: #003d6399;
}

:deep(.el-textarea) {
  --el-input-bg-color: #003d6399;
  --el-input-text-color: #ffffff;
}

:deep(.el-upload) {
  width: 260px !important;
  height: 150px !important;
  border-radius: 0px !important;
  background: #003d6399;
  border: none;
}

:deep(.el-upload-list--picture-card .el-upload-list__item) {
  width: 100% !important;
  height: 150px !important;
}

:deep(.el-upload-list--picture-card) {
  :nth-child(even) {
    display: none;
  }
}
</style>